package com.jf.springmvc.viewresolver;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.view.AbstractView;

import java.util.Map;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-10-31
 * Time:17:24
 */
@Component(value = "myView")
public class MyView extends AbstractView {
    /*
    ViewBean的id(value)值与
    自定义视图解析流程:
        1.Controller返回ModelAndView
        2.SpringMVC获得View的name
        3.按ViewResolver的优先级,逐个匹配ViewBean的id(value)
            匹配上 检测是否实现View接口
                实现 从IOC容器获得ViewBean,调用renderMergedOutputModel方法
            else 调用默认ViewResolver----InternalResourceViewResolver
     */
    @Override
    protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
        System.out.println("through my view");
        request.getRequestDispatcher("/view/success.jsp").forward(request, response);
    }
}
